<template>
  <div class="app-container">
    <!-- 导航栏 -->
    <el-card style="margin-bottom: 15px; height: 30px" shadow="always" :body-style="{ padding: '0' }">
      <div style="display: flex; line-height: 25px">
        <h1
          v-for="(item, index) in navItems"
          :key="index"
          :class="{ DynamicCondition: isActive === index, spacing: index > 0 }"
          @click="clickToSwitch(index)"
          style="font-size: 15px; cursor: pointer"
        >
          {{ item }}
        </h1>
      </div>
    </el-card>
    <!-- 楦头入库单查询 -->
    <div v-show="isActive === 1" class="ProductionDynamic">
      <Find @Launchform="Launchform5" :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList1" @findClicked="findData" />

      <el-card style="margin-top: 15px" shadow="always" :body-style="{ padding: '15px' }">
        <div class="ProductionDynamicMainCardMainL">
          <div style="width: 40%" class="ProductionDynamicMainCardMainLeft">
            <h1 class="MainLeftCardH1">单据明细</h1>
            <Table
              :isLoading="isLoading"
              @currentRow="currentRow5"
              :tableData="PunchingKnifeStorageDetailsQueryTableDate"
              :tableHeader="tableHeader2"
              :selection="false"
              :TableHeight="90"
            />
          </div>
        </div>

        <!-- 分页器 -->
      </el-card>
    </div>

    <!-- 楦头入库单建立 -->
    <div v-show="isActive === 0">
      <Find :OriginalFilter="{ static: true }" @Launchform="Launchform12" @clickNumber="clickNumber" :formList="formList" @findClicked="findData1" />

      <el-card style="margin-top: 15px" shadow="always" :body-style="{ padding: '15px' }">
        <div class="ProductionDynamicMainCardMain">
          <div class="ProductionDynamicMainCardMainLeft">
            <h1 class="MainLeftCardH1">查询资料</h1>
            <Table
              :isLoading="isLoading1"
              @currentRow1="currentRow2"
              @currentRow="currentRow1"
              :tableData="PunchingKnifeEntryListQueryTableDate"
              :tableHeader="tableHeader"
              :TableHeight="90"
            />
            <PageModule @pageSizeChange="handleSizeChangeTk" @pageChange="handleCurrentChangeTk" :PageData="{ total }" />
          </div>
        </div>
      </el-card>
    </div>

    <el-dialog v-model="dialogVisible2" width="50%">
      <Find :OriginalFilter="{ static: true }" @Launchform="Launchform13" @findClicked="findClicked12" :searchImg="false" :formList="formList2" />
    </el-dialog>

    <el-dialog v-model="dialogVisible3" width="50%">
      <Find :OriginalFilter="{ static: true }" @Launchform="Launchform14" @findClicked="findClicked14" :searchImg="false" :formList="formList5" />
    </el-dialog>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted, watch } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'PunchingStorage'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import { PunchingDataQuery, PunchingPartQuery } from '@/api/Control/FactoryControl/PunchingData'
import {
  ubdateList,
  deleteActive,
  TakeThePunchingPart,
  VenderQuery3,
  VenderQuery2,
  PunchingKnifeEntryListQuery,
  PunchingKnifeStorageDetailsQuery,
  counterCheck,
  deletecounterCheck,
  AddPunchingKnifeEntryListQuery,
  VenderQuery1
} from '@/api/Control/FactoryControl/PunchingStorage'
import LoginWork from '@/utils/LoginWork'
import { ElMessage, ElMessageBox } from 'element-plus'
const isLoading1 = ref(false)

const isLoading = ref(false)

const buttonAcitve = ref(true)

const Launchform5 = (row: any) => {
  AddPunchingKnifeEntryListQueryParms.value.slipDate = row[1].dateValue
  AddPunchingKnifeEntryListQueryParms.value.inOutType = row[2].selectValue
  AddPunchingKnifeEntryListQueryParms.value.stkName = row[3].selectValue.split(' ')[1]
  AddPunchingKnifeEntryListQueryParms.value.stkNo = row[3].selectValue.split(' ')[0]
  AddPunchingKnifeEntryListQueryParms.value.vendorName = row[4].selectValue.split(' ')[1]
  AddPunchingKnifeEntryListQueryParms.value.vendorNo = row[4].selectValue.split(' ')[0]
  AddPunchingKnifeEntryListQueryParms.value.remark = row[6].inputValue
  AddPunchingKnifeEntryListQueryParms.value.cutNo = row[5].selectValue
}

// 明细删除
const seqNo = ref('')

const currentRow5 = (row: any) => {
  seqNo.value = row.seqNo

  PunchingKnifeStorageDetailsQueryTableDate.value = PunchingKnifeStorageDetailsQueryTableDate.value.map((item: any) => {
    const newItem = JSON.parse(JSON.stringify(item)) // 创建深拷贝对象
    newItem.cutNo1Old = item.cutNo.selectValue
    newItem.partNameOld = item.partName
    return newItem
  })
}

const deleteActiveMethods = async () => {
  const result = await deleteActive(slipNoListA.value, seqNo.value)
  if (result.code === 200) {
    PunchingKnifeStorageDetailsQueryMethods()
    seqNo.value = ''
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc1 = () => {
  if (seqNo.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deleteActiveMethods()
      })
      .catch(() => {})
  }
}

// 冲刀新增
const AddPunchingKnifeEntryListQueryParmsList = ref({
  cutNo1: '',
  partName: '',
  qty: -1,
  cutStatus: '',
  remark1: ''
})

const Launchform14 = (row: any) => {
  AddPunchingKnifeEntryListQueryParmsList.value.cutStatus = row[0].selectValue
  AddPunchingKnifeEntryListQueryParmsList.value.cutNo1 = row[1].selectValue
  AddPunchingKnifeEntryListQueryParmsList.value.partName = row[2].selectValue
  AddPunchingKnifeEntryListQueryParmsList.value.qty = row[3].inputValue
  AddPunchingKnifeEntryListQueryParmsList.value.remark1 = row[4].inputValue
}

const findClicked14 = (row: any) => {
  if (row === '保存') {
    if (!isNaN(AddPunchingKnifeEntryListQueryParms.value.detail[0].qty)) {
      AddPunchingKnifeEntryListQueryParms.value.detail = [AddPunchingKnifeEntryListQueryParmsList.value]

      AddPunchingKnifeEntryListQueryMethods()
    } else {
      JMessage.warning('数量必须为数字')
    }
  }
}

// 取冲刀部位
const slipNoListA = ref('')

const cutNoListA = ref('')

const TakeThePunchingPartMethods = async () => {
  const result = await TakeThePunchingPart(slipNoListA.value, cutNoListA.value)
  if (result.code === 200) {
    PunchingKnifeStorageDetailsQueryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 修改
const updateList = ref<any>({
  cutNo: '',
  detail: [],
  inOutType: '',
  remark: '',
  slipDate: '',
  slipNo: '',
  slipType: '',
  stkName: '',
  stkNo: '',
  vendorName: '',
  vendorNo: ''
})

// const checkboxChange1 = async (row: any) => {
//   updateList.value.detail = PunchingKnifeStorageDetailsQueryTableDate.value.map((item: any) => {
//     const newItem = JSON.parse(JSON.stringify(item)); // 创建深拷贝对象
//     newItem.cutStatus = item.cutStatus.selectValue;
//     newItem.cutNo1 = item.cutNo.selectValue;
//     newItem.cutNo = item.cutNo.selectValue;
//     newItem.partName = item.partName;

//     return newItem;
//   });

//   const result = await LoginWork.put<any, any>(`/bioDeptWrok/CutInUp`, updateList.value);
//   if (result.code === 200) {
//     PunchingKnifeStorageDetailsQueryMethods();
//     JMessage.success(result.message);
//   } else {
//     JMessage.error(result.message);
//   }
//   updateList.value.detail = [];
// }

// 单独新增
const dialogVisible3 = ref(false)

// 部位资料
const cutNoList = ref('')

const PunchingPartQueryMethods = async () => {
  const result = await PunchingPartQuery(cutNoList.value)
  formList2.value[8].selectOptions = EvaluatesTheArrayReturnValue(
    result.map((item: any) => {
      return item.PART_NAME
    })
  )
  formList5.value[2].selectOptions = EvaluatesTheArrayReturnValue(
    result.map((item: any) => {
      return item.PART_NAME
    })
  )
}

watch(cutNoList, (newVal, oldval) => {
  if (newVal !== '') {
    PunchingPartQueryMethods()
  }
})

// 仓库号获取
const VenderQuery3Methods = async () => {
  const result = await VenderQuery3()
  if (result.length === 0) {
    formList2.value[6].selectOptions = [
      {
        optionKey: 1,
        optionValue: 'BF001 荣阳冲刀',
        optionLabel: 'BF001 荣阳冲刀'
      }
    ]
  } else {
    const NewArrayList = result.reduce((arr: any, item: any) => {
      if (item.ITEM_CODE && item.ITEM_NAME) {
        // 只添加非空的 typeName 和 typeNo
        arr.push(item.ITEM_CODE + ' ' + item.ITEM_NAME)
      }
      return arr
    }, [])
    formList2.value[6].selectOptions = EvaluatesTheArrayReturnValue(NewArrayList)
  }
}

const slipNoList5 = ref('')

// 双击跳转
const currentRow2 = (row: any) => {
  if (row.cfmFlag === 'Y') {
    ActiveList.value = false
    JMessage.error('已检核的数据不可修改')
  } else {
    ActiveList.value = true
    slipNoList.value = row.slipNo
    isActive.value = 1
    cutNoList.value = row.cutNo
    slipNoList5.value = row.slipNo

    updateList.value.cutNo = row.cutNo
    updateList.value.inOutType = row.inOutType
    updateList.value.remark = row.remark
    updateList.value.slipDate = row.slipDate
    updateList.value.slipNo = row.slipNo
    updateList.value.slipType = row.slipType
    updateList.value.stkName = row.stkName
    updateList.value.stkNo = row.stkNo
    updateList.value.vendorName = row.vendorName
    updateList.value.vendorNo = row.vendorNo

    AddPunchingKnifeEntryListQueryParms.value.slipNo = row.slipNo
    AddPunchingKnifeEntryListQueryParms.value.slipDate = row.slipDate
    AddPunchingKnifeEntryListQueryParms.value.inOutType = row.inOutType
    AddPunchingKnifeEntryListQueryParms.value.vendorName = row.vendorName
    AddPunchingKnifeEntryListQueryParms.value.vendorNo = row.vendorNo
    AddPunchingKnifeEntryListQueryParms.value.cutNo = row.cutNo
    AddPunchingKnifeEntryListQueryParms.value.remark = row.remark
    AddPunchingKnifeEntryListQueryParms.value.stkNo = row.stkNo
    AddPunchingKnifeEntryListQueryParms.value.stkName = row.stkName

    cutNoList1.value = row.cutNo
    // formList1.value[5].inputValue = row.cutNo
    slipNoListA.value = row.slipNo
    cutNoListA.value = row.cutNo
    PunchingKnifeStorageDetailsQueryMethods()
  }
}

// 冲刀查询
const PunchingDataQueryMethods = async () => {
  const result = await PunchingDataQuery('')
  formList.value[3].selectOptions = EvaluatesTheArrayReturnValue(
    result.map((item: any) => {
      return item.CUT_NO
    })
  )
  formList2.value[3].selectOptions = formList.value[3].selectOptions
  formList5.value[1].selectOptions = formList.value[3].selectOptions as any
  formList1.value[5].selectOptions = formList.value[3].selectOptions as any
}

const VenderQuery2MethodsTableDate = ref([])

const VenderQuery2Methods = async () => {
  const result = await VenderQuery2()
  const NewArrayList = result.reduce((arr: any, item: any) => {
    if (item.ITEM_CODE && item.ITEM_NAME) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.ITEM_CODE + ' ' + item.ITEM_NAME)
    }
    return arr
  }, [])
  VenderQuery2MethodsTableDate.value = EvaluatesTheArrayReturnValue1(NewArrayList)
  formList2.value[5].selectOptions = EvaluatesTheArrayReturnValue(NewArrayList)

  formList5.value[0].selectOptions = EvaluatesTheArrayReturnValue(NewArrayList)
}

const EvaluatesTheArrayReturnValue1 = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      value: item,
      label: item
    }
  })
}

// 新增
const Launchform13 = (row: any) => {
  cutNoList.value = row[3].selectValue
  AddPunchingKnifeEntryListQueryParms.value.remark = row[4].inputValue

  AddPunchingKnifeEntryListQueryParms.value.detail[0].cutNo1 = row[7].inputValue
  AddPunchingKnifeEntryListQueryParms.value.detail[0].partName = row[8].selectValue
  AddPunchingKnifeEntryListQueryParms.value.detail[0].qty = row[9].inputValue
  AddPunchingKnifeEntryListQueryParms.value.detail[0].remark1 = row[10].inputValue
  AddPunchingKnifeEntryListQueryParms.value.detail[0].cutStatus = row[5].selectValue.split(' ')[1]
}

const AddPunchingKnifeEntryListQueryParms = ref({
  cutNo: '',
  detail: [
    {
      cutNo1: '',
      partName: '',
      qty: -1,
      cutStatus: '',
      remark1: ''
    }
  ],
  inOutType: '',
  remark: '',
  slipDate: '',
  slipNo: '',
  slipType: '',
  stkName: '',
  stkNo: '',
  vendorName: '',
  vendorNo: ''
})

const VenderQueryMethods1 = async () => {
  const result = await VenderQuery1()
  const NewArrayList = result.reduce((arr: any, item: any) => {
    if (item.ITEM_CODE && item.ITEM_NAME) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.ITEM_CODE + ' ' + item.ITEM_NAME)
    }
    return arr
  }, [])
  formList.value[2].selectOptions = EvaluatesTheArrayReturnValue(NewArrayList)
  formList2.value[2].selectOptions = EvaluatesTheArrayReturnValue(NewArrayList)
  formList1.value[4].selectOptions = EvaluatesTheArrayReturnValue(NewArrayList)
}

const EvaluatesTheArrayReturnValue = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      optionKey: index,
      optionValue: item,
      optionLabel: item
    }
  })
}

const findClicked12 = (row: any) => {
  if (row === '保存') {
    if (!isNaN(AddPunchingKnifeEntryListQueryParms.value.detail[0].qty)) {
      AddPunchingKnifeEntryListQueryMethods()
    } else {
      JMessage.warning('数量必须为数字')
    }
  }
}

const formList2 = ref([
  {
    type: 'dateSingle',
    dateLabel: '下单日期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: 1,
        optionValue: '采购入库',
        optionLabel: '采购入库'
      },
      {
        optionKey: 2,
        optionValue: '开发入库',
        optionLabel: '开发入库'
      },
      {
        optionKey: 3,
        optionValue: '盘盈入库',
        optionLabel: '盘盈入库'
      }
    ],
    selectP: '订单类型'
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '厂商'
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '冲刀'
  },
  {
    type: 'input',
    inputPlaceholder: '备注',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '状态'
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '仓库号'
  },

  {
    type: 'input',
    inputPlaceholder: '单据明细->冲刀号',
    inputValue: ''
  },

  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '单据明细->部位'
  },

  {
    type: 'input',
    inputPlaceholder: '单据明细->数量',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '单据明细->备注',
    inputValue: ''
  },

  {
    type: 'button',
    checkboxLabel: '保存'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const formList5 = ref([
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '状态'
  },

  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '冲刀号'
  },

  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '单据明细->部位'
  },

  {
    type: 'input',
    inputPlaceholder: '单据明细->数量',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '单据明细->备注',
    inputValue: ''
  },

  {
    type: 'button',
    checkboxLabel: '保存'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const dialogVisible2 = ref(false)

const cutNoList1 = ref('')

const AddPunchingKnifeEntryListQueryMethods = async () => {
  AddPunchingKnifeEntryListQueryParms.value.detail = []

  const result = await AddPunchingKnifeEntryListQuery(AddPunchingKnifeEntryListQueryParms.value)
  if (result.code === 200) {
    AddPunchingKnifeEntryListQueryParms.value.slipNo = result.message
    slipNoList.value = result.message
    slipNoList5.value = result.message
    PunchingKnifeStorageDetailsQueryMethods()
    formList1.value[0].inputValue = result.message
    cutNoList1.value = AddPunchingKnifeEntryListQueryParms.value.cutNo
    PunchingKnifeEntryListQueryMethods()
    formList5.value.forEach((item) => {
      if (item.type === 'input') {
        item.inputValue = ''
      }
      if (item.type === 'select') {
        item.selectValue = ''
      }
    })
    dialogVisible3.value = false
    dialogVisible2.value = false

    JMessage.success('成功')
    slipNoListA.value = result.message
  } else {
    JMessage.error(result.message)
  }
}

const AddPunchingKnifeEntryListQueryMethods1 = async () => {
  AddPunchingKnifeEntryListQueryParms.value.detail = PunchingKnifeStorageDetailsQueryTableDate.value.map((item: any) => {
    item.cutStatus = item.cutStatus.selectValue
    return item
  })

  const result = await ubdateList(AddPunchingKnifeEntryListQueryParms.value)
  if (result.code === 200) {
    slipNoList.value = result.message
    PunchingKnifeStorageDetailsQueryMethods()
    formList1.value[0].inputValue = result.message
    PunchingKnifeEntryListQueryMethods()
    formList5.value.forEach((item) => {
      if (item.type === 'input') {
        item.inputValue = ''
      }
      if (item.type === 'select') {
        item.selectValue = ''
      }
    })
    dialogVisible3.value = false
    dialogVisible2.value = false

    JMessage.success('成功')
    slipNoListA.value = result.message
  } else {
    JMessage.error(result.message)
  }
}

// 整单删除
const deleteSlipNo = ref('')

const deletecounterCheckMethods = async () => {
  const result = await deletecounterCheck(deleteSlipNo.value)
  if (result.code === 200) {
    PunchingKnifeEntryListQueryMethods()
    deleteSlipNo.value = ''
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc = () => {
  if (deleteSlipNo.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deletecounterCheckMethods()
      })
      .catch(() => {})
  }
}

// 检核
const slipNoAny = ref('')

const findData1 = (count: string) => {
  if (count === '检核') {
    if (slipNoAny.value === '') {
      JMessage.warning('请选择需要检核的数据')
    } else {
      counterCheckMethods()
    }
  }
  if (count === '整单删除') {
    handleCloseMateriaLKlc()
  }
  if (count === '新增') {
    VenderQuery3Methods()
    dialogVisible2.value = true
  }
  if (count === '置空') {
    formList.value.forEach((item) => {
      if (item.type === 'input') {
        item.inputValue = ''
      }
      if (item.type === 'select') {
        item.selectValue = ''
      }
      if (item.type === 'date') {
        item.dateValue = ''
      }
    })
  }
}

const currentRow1 = (row: any) => {
  slipNoAny.value = row.slipNo
  deleteSlipNo.value = row.slipNo
}

const counterCheckMethods = async () => {
  const result = await counterCheck(slipNoAny.value)
  if (result.code === 200) {
    PunchingKnifeEntryListQueryMethods()
    slipNoAny.value = ''
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 冲刀明细查询
const slipNoList = ref('')

const ActiveList = ref(false)

const PunchingKnifeStorageDetailsQueryTableDate = ref<any>([])

const PunchingKnifeStorageDetailsQueryMethods = async () => {
  isLoading.value = true
  const result = await PunchingKnifeStorageDetailsQuery(slipNoList.value)

  if (result.details !== null) {
    if (ActiveList.value) {
      PunchingKnifeStorageDetailsQueryTableDate.value = result.details.map((item: any) => {
        item.change = 'Y'
        item.disableConfirm = true
        item.cutStatus = {
          selectValue: item.cutStatus,
          options: VenderQuery2MethodsTableDate
        }
        // item.cutNo = {
        //   selectValue: item.cutNo || '',
        //   options: EvaluatesTheArrayReturnValue1(formList5.value[1].selectOptions?.map((item: any) => {
        //     return item.optionValue
        //   }))
        // }

        // item.cutStatus = {
        //   selectValue: item.cutStatus,
        //   options: VenderQuery2MethodsTableDate
        // }
        // item.cutNo = {
        //   selectValue: item.cutNo || '',
        //   options: EvaluatesTheArrayReturnValue1(formList5.value[1].selectOptions?.map((item: any) => {
        //     return item.optionValue
        //   }))
        // }

        item.cutNo1 = item.cutNo
        return item
      })
    } else {
      PunchingKnifeStorageDetailsQueryTableDate.value = result.details.map((item: any) => {
        item.cutStatus = {
          selectValue: item.cutStatus,
          options: VenderQuery2MethodsTableDate
        }
        // item.cutNo = {
        //   selectValue: item.cutNo || '',
        //   options: EvaluatesTheArrayReturnValue1(formList5.value[1].selectOptions?.map((item: any) => {
        //     return item.optionValue
        //   }))
        // }

        //  item.cutStatus = {
        //    selectValue: item.cutStatus,
        //    options: VenderQuery2MethodsTableDate
        //  }
        // item.cutNo = {
        //   selectValue: item.cutNo || '',
        //   options: EvaluatesTheArrayReturnValue1(formList5.value[1].selectOptions?.map((item: any) => {
        //     return item.optionValue
        //   }))
        // }

        item.cutNo1 = item.cutNo
        return item
      })
    }
  } else {
    PunchingKnifeStorageDetailsQueryTableDate.value = []
  }

  formList1.value[0].inputValue = result.slipNo
  formList1.value[1].dateValue = result.slipDate
  formList1.value[2].selectValue = result.inOutType
  formList1.value[3].selectValue = result.stkNo + ' ' + result.stkName
  formList1.value[4].selectValue = result.vendorNo + ' ' + result.vendorName
  formList1.value[6].inputValue = result.remark
  formList1.value[5].selectValue = result.cutNo
  formList1.value[7].inputValue = result.slipNo
  formList1.value[8].inputValue = result.cfmFlag
  isLoading.value = false
}

// 冲刀入库单查询
const PunchingKnifeEntryListQueryParms = ref({
  cfmFlag: 1,
  cutNo: '',
  cutStatus: '',
  inOutType: '',
  pageNum: 1,
  pageSize: 40,
  partName: '',
  slipDateEnd: '',
  slipDateStart: '',
  vendorNo: ''
})

const Launchform12 = (row: any) => {
  PunchingKnifeEntryListQueryParms.value.slipDateStart = row[0].dateValue[0]
  PunchingKnifeEntryListQueryParms.value.slipDateEnd = row[0].dateValue[1]
  PunchingKnifeEntryListQueryParms.value.inOutType = row[1].selectValue
  PunchingKnifeEntryListQueryParms.value.vendorNo = row[2].selectValue.split(' ')[0]
  PunchingKnifeEntryListQueryParms.value.partName = row[4].inputValue
  PunchingKnifeEntryListQueryParms.value.cutNo = row[3].selectValue
  PunchingKnifeEntryListQueryMethods()
}

const clickNumber = (num: number) => {
  PunchingKnifeEntryListQueryParms.value.cfmFlag = Number(num)
  PunchingKnifeEntryListQueryMethods()
}

const handleSizeChangeTk = (val: number) => {
  PunchingKnifeEntryListQueryParms.value.pageSize = val
  PunchingKnifeEntryListQueryMethods()
}

const handleCurrentChangeTk = (val: number) => {
  PunchingKnifeEntryListQueryParms.value.pageNum = val
  PunchingKnifeEntryListQueryMethods()
}

const total = ref(0)

const clearformList1 = () => {
  formList1.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'input1') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
    if (item.type === 'dateSingle') {
      item.dateValue = ''
    }
  })
}

const PunchingKnifeEntryListQueryTableDate = ref([])

const PunchingKnifeEntryListQueryMethods = async () => {
  isLoading1.value = true
  const result = await PunchingKnifeEntryListQuery(PunchingKnifeEntryListQueryParms.value)
  PunchingKnifeEntryListQueryTableDate.value = result.dtos
  total.value = result.total
  isLoading1.value = false
}

onMounted(() => {
  PunchingKnifeEntryListQueryMethods()

  VenderQueryMethods1()

  PunchingDataQueryMethods()

  VenderQuery2Methods()
})

// 导航栏
const navItems = ref(['冲刀入库单查询', '冲刀入库单建立'])

// 导航栏状态
const isActive = ref(0)

const formList = ref([
  {
    type: 'date',
    dateLabel: '单据日期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: 1,
        optionValue: '采购入库',
        optionLabel: '采购入库'
      },
      {
        optionKey: 2,
        optionValue: '开发入库',
        optionLabel: '开发入库'
      },
      {
        optionKey: 3,
        optionValue: '盘盈入库',
        optionLabel: '盘盈入库'
      }
    ],
    selectP: '入库类型'
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '厂商'
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '冲刀'
  },
  {
    type: 'input',
    inputPlaceholder: '请输入部位',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'radio',
    checkboxLabel: '已确认',
    checked: false,
    label: '1'
  },
  {
    type: 'radio',
    checkboxLabel: '未确认',
    checked: false,
    label: '0'
  },
  {
    type: 'button',
    checkboxLabel: '新增'
  },
  {
    type: 'button',
    checkboxLabel: '整单删除'
  },
  {
    type: 'button',
    checkboxLabel: '检核'
  },
  {
    type: 'button',
    checkboxLabel: '打印入库单'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const formList1 = ref([
  {
    type: 'input1',
    inputPlaceholder: '请输入单据号',
    inputValue: '',
    inputDisabled: true
  },
  {
    type: 'dateSingle',
    dateLabel: '单据日期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: 1,
        optionValue: '采购退库',
        optionLabel: '采购退库'
      },
      {
        optionKey: 2,
        optionValue: '盘盈出库',
        optionLabel: '盘盈出库'
      }
    ],
    selectP: '入库类型'
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: 1,
        optionValue: 'BF 荣阳冲刀',
        optionLabel: 'BF 荣阳冲刀'
      }
    ],
    selectP: '仓库'
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '厂商'
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '冲刀号'
  },
  {
    type: 'input',
    inputPlaceholder: '',
    inputValue: '',
    inputLabel: '备注:'
  },
  {
    type: 'input',
    inputPlaceholder: '',
    inputValue: '',
    inputLabel: '订购单号:'
  },
  {
    type: 'input1',
    inputPlaceholder: '',
    inputValue: '',
    inputLabel: '检核标记:',
    inputDisabled: true
  },
  {
    type: 'button',
    checkboxLabel: '增加明细'
  },
  {
    type: 'button',
    checkboxLabel: '增加',
    disabled: buttonAcitve
  },
  {
    type: 'button',
    checkboxLabel: '保存'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  },
  {
    type: 'button',
    checkboxLabel: '取冲刀部位'
  },
  {
    type: 'button',
    checkboxLabel: '取订购单资料'
  }
])

const findData = (data: any) => {
  switch (data) {
    case '增加明细': {
      PunchingKnifeStorageDetailsQueryTableDate.value.push({
        cutNo: cutNoList1.value,
        partName: '',
        qty: '',
        cutStatus: {
          selectValue: '',
          options: VenderQuery2MethodsTableDate
        },
        remark1: '',
        change: 'Y',
        disableConfirm: true,
        slipNo: slipNoList5.value
      })
      break
    }
    case '取冲刀部位': {
      TakeThePunchingPartMethods()
      break
    }
    case '删除': {
      handleCloseMateriaLKlc1()
      break
    }
    case '增加': {
      AddPunchingKnifeEntryListQueryMethods()
      break
    }
    case '保存': {
      AddPunchingKnifeEntryListQueryMethods1()
      break
    }
  }
}

// 表格数据

const tableHeader = ref([
  {
    label: '单据号',
    prop: 'slipNo'
  },
  {
    label: '单据日期',
    prop: 'slipDate'
  },
  {
    label: '入库类型',
    prop: 'inOutType'
  },
  {
    label: '仓库',
    prop: 'stkName'
  },
  {
    label: '厂商',
    prop: 'vendorName'
  },
  {
    label: '冲刀号',
    prop: 'cutNo'
  },
  {
    label: '部位',
    prop: 'partName'
  },
  {
    label: '数量',
    prop: 'qty'
  },
  {
    label: '状态',
    prop: 'cutStatus'
  },
  {
    label: '备注信息',
    prop: 'remark1'
  },
  {
    label: '检核',
    prop: 'cfmFlag'
  }
])

const tableHeader2 = ref([
  {
    label: '冲刀号',
    prop: 'cutNo',
    change: true
    // type: 'select',
    // change:false
  },
  {
    label: '部位',
    prop: 'partName'
  },
  {
    label: '数量',
    prop: 'qty'
  },
  {
    label: '状态',
    prop: 'cutStatus',
    type: 'select'
  },
  {
    label: '备注信息',
    prop: 'remark1'
  }
])

//点击切换
const clickToSwitch = (index: number) => {
  isActive.value = index
  if (index === 1) {
    buttonAcitve.value = false
    PunchingKnifeStorageDetailsQueryTableDate.value = []
    clearformList1()
  } else {
    buttonAcitve.value = true
  }
}
</script>

<style lang="less" scoped>
.H1Size {
  font-size: 16px;
}

.bottom {
  float: right;
}

.DynamicCondition {
  color: #f89027;
  border-bottom: 2px solid #f89027;
}

.spacing {
  margin-left: 15px;
  /* 根据需要调整间距大小 */
}

.save {
  color: black;
  border: 1px solid #e7e7e7;
  background: #e7e7e7;
}

.ProductionDynamicMainCardMainLeft {
  width: 70%;
}

.MainLeftCardH1 {
  font-size: 20px;
}
</style>
